<template>
    <div class="wrap">
        <div class="result">
            <div class="searchcontent">搜索内容：{{$route.query.searchContent}}</div>
            <div class="list" v-show="isshow">
                <div class="item" v-for="item in searchDate" :key="item._id" @click="goDetails(item)">
                    <div class="name">{{item.name}}</div>
                    <div class="content">
                        {{item.content}}
                    </div>
                    <div class="postsinfo">
                        <div class="arouthname">admin19</div>
                        <div class="time">{{item.addTime}}</div>
                    </div>
                </div>
            </div>
            <div class="null" v-show="!isshow">抱歉，没有找到您要搜索的内容哦</div>
        </div>

       <HomeFooter/>
    </div>
</template>

<script>
    import {mapState} from 'vuex'
    import HomeFooter from '@/components/HomeFooter'
    export default {
        name:"Search-Result",
        components:{HomeFooter},
        data(){
            return {
                isshow:true
            }
        },
        methods: {
            // 获取数据请求
            getSearchResult(content){
                this.$store.dispatch('Home/search',content)
            },
            // 获取作者信息
            getArouthInfo(_id){
                this.$store.dispatch('Home/getArouth',_id)
            },

            // 跳转详情页
            goDetails(item){
                //获取作者信息
                this.getArouthInfo(item.arouth)
                // 增加浏览量
                this.$store.dispatch('Home/addLook',item._id)
                setTimeout(()=>{
                    this.$set(item,'arouthName',this.arouthInfo)
                    this.$router.push({
                        path:"/blogDetails",
                        query:item
                    })
                },20)
            }
        },
        computed:{
            ...mapState('Home',['searchDate','arouthInfo'])
        },
        mounted() {
            this.getSearchResult(this.$route.query.searchContent),
            setTimeout(()=>{
                if(!this.searchDate){
                    this.isshow = false
                }
            },20)
        },
    }
</script>

<style scoped lang="less">
    .wrap{
        width: 100%;
        background: #F0F2F5;

        .result{
            width: 80%;
            // height: 30vw;
            margin: 0 auto;

            .searchcontent{
                text-align: center;
                font-size: 2vw;
                padding:1.3vw 0;
                background: #fff;
            }

            .list{
                width: 100%;
                padding: 3.3vw 0;

                .item{
                    // width: 100%;
                    background: #fff;
                    // height: 8vw;
                    padding: 1vw 2vw;
                    cursor: pointer;
                    margin-bottom: 1vw;

                    &:hover{
                        box-shadow: 0 0 5px 5px rgba(219, 219, 219, 0.26);
                    }

                    .name{
                        font-size: 1.8vw;
                        color: rgb(100, 100, 100);
                        margin-bottom: 1.3vw;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap; 
                        font-weight: 1000;

                        &:hover{
                            text-decoration: underline;
                        }
                    }

                    .content{
                        // text-indent: 2em;
                        overflow: hidden;
                        display: -webkit-box;
                        text-overflow: ellipsis;
                        -webkit-line-clamp: 1;
                        -webkit-box-orient: vertical;
                        color: rgb(100, 100, 100);
                        line-height: 30px;
                    }

                    .postsinfo{
                        display: flex;
                        padding: 0.7vw 0;
                        justify-content: right;
                        color: #ccc;

                        .arouthname{
                            margin-right: 2vw;
                            
                        }
                    }
                }
            }

            .null{
                background: #fff;
                height: 10vw;
                line-height: 9.8vw;
                text-align: center;
                font-size: 2vw;
            }
        }
    }
</style>